﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class Comment_ListController : UserController
    {
        public IArticle_commentService _article_comment { get; set; }
        [HttpGet]
        public IActionResult Get(int article_id,int page = 1, int page_size = 20)
        {       
            if (article_id == 0 || page_size == 0)
            {
                return Ok(new { status=0,msg= "传输参数有误" });
            }
            page = page > 0 ? page : 1;
            string strwhere = "where is_lock=0 and article_id=" + article_id;
            var list = _article_comment.GetList(page, page_size, strwhere, "add_time desc,id desc");
            int totalcount = _article_comment.RecordCount(strwhere);
            int pageCount = totalcount / page_size;
            if (pageCount < 1)
            {
                pageCount = 1;
            }
            if (totalcount % page_size > 0)
            {
                pageCount += 1;
            }
            if (pageCount <= 1)
            {
                pageCount = 1;
            }
            return Ok(new { status = 1, list = list, page = page, page_count = pageCount, total_count = totalcount });
        }
    }
}